package com.znh.entity;

import com.znh.common.Utils;
import com.znh.enums.PieceActionEnum;
import com.znh.enums.PieceInitLocationEnum;
import com.znh.enums.PiecePlayerEnum;

import java.awt.*;
import java.util.List;

/**
 * @version 1.0
 * @Author znh
 * @Date 2024/5/24 下午3:30
 * @注释 兵/卒类
 */
public class Bing extends Piece {
    public Bing(int id, Point point, PiecePlayerEnum player, PieceInitLocationEnum initLocation) {

        super(id, "bing", point, player, initLocation,
                new StringBuilder().append("images/bing")
                        .append(player == PiecePlayerEnum.RED ? "0" : "1").append(".png").toString());
    }

    @Override
    public boolean isMove(Point tp) {
        PieceActionEnum action = action(tp);
        if (!isCrossRiver(this.getPoint())) {
            //过河前：是否走直线(Y)、是否前进、步数是否为1
            return action == PieceActionEnum.LINEY && isForward(tp) && getStep(tp, PieceActionEnum.LINEY) == 1;
        } else {
            //过河后：是否走直线(X、Y)、是否后退、步数是否为1
            return (action == PieceActionEnum.LINEY && !isRetreat(tp) && getStep(tp, PieceActionEnum.LINEY) == 1)//过河后前进
                    || (action == PieceActionEnum.LINEX && !isRetreat(tp) && getStep(tp, PieceActionEnum.LINEX) == 1);//过河后左右移动
        }
    }

    @Override
    public boolean simulateMove(Point tp) {
        return isMove(tp) && super.simulateMove(tp);
    }
}
